package org.msb.accentis.gui.swing;

import javax.swing.JTabbedPane;

public class ValidatingTabbedPane extends JTabbedPane {

	private Validator validator;
	
	public ValidatingTabbedPane(Validator validator) {
		this.validator = validator;
	}

	public ValidatingTabbedPane(int tabPlacement, int tabLayoutPolicy, Validator validator) {
		super(tabPlacement, tabLayoutPolicy);
		this.validator = validator;
	}

	public ValidatingTabbedPane(int tabPlacement, Validator validator) {
		super(tabPlacement);
		this.validator = validator;
	}

	@Override
	public void setSelectedIndex(int index) {
		if (null != validator && validator.canSwitchTabs(index))
			super.setSelectedIndex(index);
	}

	public interface Validator {
		
		public boolean canSwitchTabs(int newTabIndex);
	}
	
}
